import os

temp_dir = "temp"
if not os.path.exists(temp_dir):
    os.mkdir(temp_dir)
temp_file = os.path.join(temp_dir, "text.txt")
print(os.path.abspath(temp_file))
with open(temp_file, "w") as f:
    f.write("Hello World")
dir_fd = os.open(temp_file, os.O_RDONLY)  # Open the directory

# file_info = os.stat('text.txt', dir_fd=dir_fd)
file_info = os.stat(temp_file)
print(f'File size:{file_info.st_size}')
os.close(dir_fd)  # Close the directory
# os.remove(temp_file)
# os.rmdir(temp_dir)
# os.symlink(temp_file, 'text_symlink.txt')
# 获取软链接信息
file_info = os.stat('text_symlink.txt')
print(f'File size:{file_info.st_size}')
link_info = os.stat('text_symlink.txt', follow_symlinks=False)
# 删除软链接
os.unlink('text_symlink.txt')
